<?php 
defined('IN_DESTOON') or exit('Access Denied');
$itemid or dheader($MOD['linkurl']);
if(!check_group($_groupid, $MOD['group_show'])) include load('403.inc');
require DT_ROOT.'/module/'.$module.'/common.inc.php';
require DT_ROOT.'/module/member/member.class.php';

$item = $db->get_one("SELECT * FROM {$table} WHERE itemid=$itemid");
if($item && $item['status'] > 2) {
	if($item['islink']) dheader($item['linkurl']);
	if($MOD['show_html'] && is_file(DT_ROOT.'/'.$MOD['moduledir'].'/'.$item['linkurl'])) d301($MOD['linkurl'].$item['linkurl']);
	extract($item);
        if( empty($item['zp_type']) )
        {
            if( empty($item['zp_number']) ) $item['zp_number'] = "-";
            if( empty($item['zp_user1']) ) $item['zp_user1'] = "-";
            if( empty($item['zp_user2']) ) $item['zp_user2'] = "-";
            if( empty($item['zp_source']) ) $item['zp_source'] = "-";
            if( empty($item['tag']) ) $item['tag'] = "-";
            if( empty($item['zp_starttime']) )
                $item['zp_starttime'] = "-";
            else 
                $item['zp_starttime'] = date('Y-m-d H:i', $item['zp_starttime']);
            
        }
} else {
	include load('404.inc');
}
$CAT = get_cat($catid);
if(!check_group($_groupid, $CAT['group_show'])) include load('403.inc');
$content_table = content_table($moduleid, $itemid, $MOD['split'], $table_data);
$t = $db->get_one("SELECT content FROM {$content_table} WHERE itemid=$itemid");
$content = $t['content'];
if($lazy) $content = img_lazy($content);
$CP = $MOD['cat_property'] && $CAT['property'];
if($CP) {
	require DT_ROOT.'/include/property.func.php';
	$options = property_option($catid);
	$values = property_value($moduleid, $itemid);
}
$adddate = timetodate($addtime, 3);
$editdate = timetodate($edittime, 3);
if($voteid) $voteid = explode(' ', $voteid);
if($fromurl) $fromurl = fix_link($fromurl);
$linkurl = $MOD['linkurl'].$linkurl;
$titles = array();
if($subtitle) {
	$titles = explode("\n", $subtitle);
	$titles = array_map('trim', $titles);
}
$subtitle = isset($titles[$page-1]) ? $titles[$page-1] : '';
$keytags = $tag ? explode(' ', $tag) : array();
$update = '';
$fee = get_fee($item['fee'], $MOD['fee_view']);
if($fee) {
	$user_status = 4;
	$destoon_task = "moduleid=$moduleid&html=show&itemid=$itemid&page=$page";
	$description = get_description($content, $MOD['pre_view']);
} else {
	$user_status = 3;
}
$pages = '';
$subtitles = count($titles);
$total = 1;
if(strpos($content, '<hr class="de-pagebreak" />') !== false) {
	$content = explode('<hr class="de-pagebreak" />', $content);
	$total = count($content);
	$pages = pages($total, $page, 1, $MOD['linkurl'].itemurl($item, '{destoon_page}'));
	if($pages) $pages = substr($pages, 0, strpos($pages, '<cite>'));
	$content = isset($content[$page-1]) ? $content[$page-1] : '';
	if($total < $subtitles) $subtitles = $total;
}
if($page > $total) include load('404.inc');
if($MOD['keylink']) $content = keylink($content, $moduleid);
include DT_ROOT.'/include/update.inc.php';
$seo_file = 'show';
include DT_ROOT.'/include/seo.inc.php';
if($EXT['mobile_enable']) $head_mobile = $EXT['mobile_url'].mobileurl($moduleid, 0, $itemid, $page);
if($subtitle) $seo_title = $subtitle.$seo_delimiter.$seo_title;
$template = 'show';
if($MOD['template_show']) $template = $MOD['template_show'];
if($CAT['show_template']) $template = $CAT['show_template'];
if($item['template']) $template = $item['template'];

// 
// inserted by ujh 2016.08.03 -- begin -- 
$check_user_enable = false;
$check_login = false;
$check_article_permision = false;
$check_time = false;
$check_category = false;
$check_area = false;
$check_filtercategory = false;
//$groupfind = array();
$searchday_limit = false;
$check_clicklimit = false;

// get user
$user=array();

if( !empty($_userid) )
{
    $do_member = new member;
    $do_member->userid = $_userid;
    $user = $do_member->get_one();

    if( !empty($user))
    {
        $check_login = true;
    }
}

if( $moduleid != 23 ) // if else zhaobiao 
{
    $check_user_enable = true;
    $check_article_permision = true;
    $check_time = true;
    $check_category = true;
    $check_area = true;
    $check_filtercategory = true;
    $check_clicklimit = true;
}
else
{
    // check category id and filter category and filter address
    // $item['filtercategory'], $item['filteraddress'], $item['catid']
    // $user[zp_starttime], $user[zp_endtime], $user[zp_filteraddress],  $user[zp_filtercategory], $user[zp_category]
    
    if( $user['groupid'] <= 1 )
    {
        $check_user_enable = true;
        $check_time = true;
        $check_category = true;
        $check_area = true;
        $check_filtercategory = true;
        $check_article_permision = true;
        $check_clicklimit = true;
    }
    //else
    //{
    //    $groupfind = $db->get_one("SELECT * FROM {$db->pre}member_group where groupid=".$user['groupid']);
    //}
    
    if( !empty($MG['searchday_limit']) )
        $searchday_limit = $MG['searchday_limit']; 
    
    $dailyclick_limit = 0;
    if( !empty($MG['dailyclick_limit']) )
        $dailyclick_limit = intval ($MG['dailyclick_limit']); 
    
    // get current time 
    $current_time = date("Y-m-d", time());
    
    // if -1 then no limit
    if( $dailyclick_limit < 0 )
    {
        $check_clicklimit = true;
    }
    
    if( $dailyclick_limit > 0 && !empty($do_member) )
    {
        $clicks = $do_member->getDayClicks($current_time);
        if(empty($clicks) || intval($clicks['click_count']) < $dailyclick_limit )
        {
            $check_clicklimit = true;
            $do_member->incClicks();
        }
    }
    
    // check enable
    if( !empty($user['zp_enable']) && ( $user['zp_enable'] == "1" || $user['zp_enable'] == 1 ) )
        $check_user_enable = true;
    
    // check time 
    $start_time = $user['zp_starttime'];
    $end_time = $user['zp_endtime'];
    
    if( !empty($start_time) )
    {
        $check_article_permision = true;
    }
    
    if(  strcmp($start_time, $current_time ) < 0 &&  strcmp($current_time, $end_time ) < 0  )
    {
        $check_time = true;
    }
    
    // check zhaobiao category
    if( empty($user['zp_category']) )
    {
        $check_category = true;
    }
    else
    {
        // check all         
        $pos = strpos($user['zp_category'], "(0)");
        if ($pos !== false) {
            $check_category = true;
        }
        else 
        {
            $pos = strpos($user['zp_category'], "(" . $item['catid'] .  ")");
            if ($pos !== false) {
                $check_category = true;
            }
        }        
    }
    
    // check zhaobiao area
    if( !$check_area && empty($user['zp_filteraddress']) )
    {
        $check_area = true;
    }
    if( !$check_area && empty($item['filteraddress']) )
    {
        $check_area = true;
    }
    
    if( !$check_area )
    {
        // check all         
        $pos = strpos($user['zp_filteraddress'], "(0)");
        if ($pos !== false) {
            $check_area = true;
        }
    }
    
    if( !$check_area )
    {
        // check all         
        $pos = strpos($item['filteraddress'], "(0)");
        if ($pos !== false) {
            $check_area = true;
        }
    }
    
    if( !$check_area )
    {
        $user_areas = array();
        preg_match_all("/\(\d+\)/",  $user['zp_filteraddress'],  $user_areas );
        
        $zb_areas = array();
        preg_match_all("/\(\d+\)/",  $item['filteraddress'],  $zb_areas );
         
        foreach( $user_areas[0] as $ua )
        {
            if( $check_area )
                break;
            
            foreach( $zb_areas[0] as $za )
            {
                if( $check_area )
                    break;
                
                if( strcmp($ua, $za) == 0 )
                {
                    $check_area = true;
                }
            }
        }
    }    
        
    // check zhaobiao filter category
    if( !$check_filtercategory && empty($user['zp_filtercategory']) )
    {
        $check_filtercategory = true;
    }
    if( !$check_filtercategory && empty($item['filtercategory']) )
    {
        $check_filtercategory = true;
    }
    
    if( !$check_filtercategory )
    {
        // check all         
        $pos = strpos($user['zp_filtercategory'], "(0)");
        if ($pos !== false) {
            $check_filtercategory = true;
        }
    }
    
    if( !$check_filtercategory )
    {
        // check all         
        $pos = strpos($item['filtercategory'], "(0)");
        if ($pos !== false) {
            $check_filtercategory = true;
        }
    }
    
    if( !$check_filtercategory )
    {
        $user_areas = array();
        preg_match_all("/\(\d+\)/",  $user['zp_filtercategory'],  $user_areas );
        
        $zb_areas = array();
        preg_match_all("/\(\d+\)/",  $item['filtercategory'],  $zb_areas );
         
        foreach( $user_areas[0] as $ua )
        {
            if( $check_filtercategory )
                break;
            
            foreach( $zb_areas[0] as $za )
            {
                if( $check_filtercategory )
                    break;
                
                if( strcmp($ua, $za) == 0 )
                {
                    $check_filtercategory = true;
                }
            }
        }
    }
}

// inserted by ujh 2016.08.03 -- end -- 
//

include template($template, $module);
?>